import 'package:cbec_app/components/common/dashed_line.dart';
import 'package:flutter/material.dart';

class SpecialDividingLine extends StatelessWidget {
  final Color painterColor;
  final Color lineColor;
  const SpecialDividingLine({super.key, this.lineColor = Colors.white, this.painterColor = Colors.white});

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        // 上半圆
        CustomPaint(
          size: const Size(10, 10),
          painter: HalfCirclePainter(painterColor: painterColor, isTop: true),
        ),
        // 中间虚线
        Expanded(
          child: DashedLind(
            axis: Axis.vertical,
            dashedWidth: 1,
            color: lineColor,
            count: 20,
          ),
        ),
        // 下半圆
        CustomPaint(
          size: const Size(10, 10),
          painter: HalfCirclePainter(painterColor: painterColor, isTop: false),
        ),
      ],
    );
  }
}

// 半圆绘制
class HalfCirclePainter extends CustomPainter {
  final bool isTop;
  final Color painterColor;

  HalfCirclePainter({this.painterColor = Colors.white, this.isTop = true});

  @override
  void paint(Canvas canvas, Size size) {
    final Paint paint = Paint()
      ..color = painterColor
      ..style = PaintingStyle.fill;

    final Path path = Path();
    if (isTop) {
      // 顶部半圆，向下
      path.moveTo(0, 0); // 起点
      path.quadraticBezierTo(size.width / 2, size.height, size.width, 0); // 控制点在中间，终点在右边
    } else {
      // 底部半圆，向上
      path.moveTo(0, size.height); // 起点
      path.quadraticBezierTo(size.width / 2, 0, size.width, size.height); // 控制点在中间，终点在右边
    }

    path.close();
    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
